import 'package:flutter/material.dart';
import 'package:flutter_app/components/layout.dart';

class FundDetailPage extends StatefulWidget {
  @override
  _FundDetailPageState createState() => _FundDetailPageState();
}

Widget WarningText(String text, {TextStyle style}) {
  return Text(
    text,
    style:
        style ?? TextStyle(color: Color(0xFF8B90A4), height: 1.7, fontSize: 13),
  );
}

Widget RuleContentTitle(String text) {
  return Container(
    margin: EdgeInsets.only(right: 20.0),
      child: Text(
    text,
    style: TextStyle(color: Color(0xFF05EFE6)),
  ));
}
Widget RuleContentItemVal(String text){
  return Text(text,style: TextStyle(color: Colors.white,fontSize: 13),);

}

class _FundDetailPageState extends State<FundDetailPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  List tabs = ["买入规则", "赎回规则"];

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  void initState() {
    super.initState();
    // 创建Controller
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            brightness: Brightness.dark,
            backgroundColor: Color(0xFF2E3347),
            elevation: 0,
        ),
      body: Container(
        width: MediaQuery.of(context).size.width,
        padding: EdgeInsets.symmetric(horizontal: 20.0),
        decoration: BoxDecoration(color: Color(0xFF2E3347)),
        child: Column(
          children: [
            Expanded(
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    SizedBox(
                      height: 20,
                    ),
                    Container(
                      padding: EdgeInsets.symmetric(
                          horizontal: 15.0, vertical: 15.0),
                      decoration: BoxDecoration(color: Color(0xFF171A2B)),
                      child: Column(
                        children: [
                          TabBar(
                              //生成Tab菜单
                              controller: _tabController,
                              labelColor: Color(0xFF05EFE6),
                              labelStyle: TextStyle(fontSize: 16),
                              unselectedLabelColor: Colors.grey,
                              indicatorColor: Color(0xFF05EFE6),
                              // indicatorSize: TabBarIndicatorSize.label,
                              indicatorWeight: 3.0,
                              tabs: tabs.map((e) => Tab(text: e)).toList()),
                          Container(
                            height:260,
                            child: TabBarView(
                                controller: _tabController,
                                children: [

                                //  赎回规则
                                  Column(
                                    children: [
                                      SizedBox(
                                        height: 20,
                                      ),
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RuleContentTitle('投资金额'),
                                          Expanded(
                                            child: RuleContentItemVal('1BTC起投，个人限额50BTC'),
                                          )
                                        ],
                                      ),
                                      SizedBox(
                                        height: 20,
                                      ),
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RuleContentTitle('产品净值'),
                                          Expanded(
                                            child: RuleContentItemVal('募集期结束后确认初始产品净值。后续每月第一周更新一次产品净值。'),
                                          )
                                        ],
                                      ),
                                      SizedBox(
                                        height: 20,
                                      ),
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RuleContentTitle('投资份额'),
                                          Expanded(
                                            child: RuleContentItemVal('募集期结束后根据当前产品净值确认购买份额。投资人在进行赎回时，可赎回所持有的全部或者部分份额。'),
                                          )
                                        ],
                                      ),
                                      SizedBox(
                                        height: 20,
                                      ),
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RuleContentTitle('持有金额'),
                                          Expanded(
                                            child: RuleContentItemVal('持有金额 = 持有份额 * 最新产品净值'),
                                          )
                                        ],
                                      ),
                                      SizedBox(
                                        height: 20,
                                      ),
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RuleContentTitle('申购费率'),
                                          Expanded(
                                            child: Row(
                                              children: [
                                                Text('1% ',style: TextStyle(
                                                  color: Colors.white,
                                                  decoration: TextDecoration.lineThrough,
                                                  decorationColor: Colors.red,
                                                  decorationStyle: TextDecorationStyle.double
                                                ),),
                                                RuleContentItemVal('(本产品首次募集不收取申购费用)'),
                                              ],
                                            ),
                                          )
                                        ],
                                      )
                                    ],
                                  ),
                                  Column(
                                    children: [
                                      SizedBox(
                                        height: 20,
                                      ),
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RuleContentTitle('封闭规则'),
                                          Expanded(
                                              child:
                                              RuleContentItemVal('封闭期6个月，封闭期内不支持主动赎回')),
                                        ],
                                      ),
                                      SizedBox(
                                        height: 20,
                                      ),
                                      Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          RuleContentTitle('其他费用'),
                                          Expanded(
                                              child: RuleContentItemVal(
                                                  '基金赎回可能产生赎回费用，以封闭期结束开放赎回时规则为准。')),
                                        ],
                                      ),
                                    ],
                                  ),
                                ]),
                          )
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    //风险提示
                    Wrap(
                      runSpacing: 15.0,
                      children: [
                        Center(
                            child: Text(
                          '- 风险提示 -',
                          style:
                              TextStyle(color: Color(0xFF8B90A4), fontSize: 16),
                        )),
                        WarningText(
                            '1.数字资产本身不由任何金融机构或公司发行。数字资产市场是全新的，未经确认的。数字资产交易存在极高风险，其全天不间断交易，没有涨跌限制。数字资产的价值上下浮动剧烈，您购买、出售、持有或者投资数字资产或相关产品可能存在资金亏损的巨大风险，并不适合绝大部分人士。您应根据您的财务状况和风险偏好，仔细考虑您是否适合投资该等资产管理产品。'),
                        WarningText('2.本资产管理产品非保本产品，您不应将本资产管理产品视为普通储蓄或存款的替代品。'),
                        WarningText(
                            '3.我们向您提供的任何有关预期收益的信息仅供参考，并不代表我们就该等预期收益进行任何形式的承诺和保证。'),
                        WarningText('4.一旦您投资本资产管理产品，在封闭期内任何提前赎回或者支取都将不被允许。'),
                        WarningText(
                            '5.公司提供的与该等资产管理产品有关的任何信息(包括但不限于网站，订单系统，产品页面)均不构成向美国，中国香港，新加坡以及其他禁止发出类似要约出售和索取购买要约的国家或地区的居民发出要约出售或索取购买要约。在您投资本资产管理产品之前，请您确认您不是上述国家或地区的居民，并且您对资产管理产品的投资符合适用于您的法律法规。')
                      ],
                    )
                  ],
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 10.0),
              child: Row(
                children: [
                  Expanded(
                    child: FlatButton(
                      onPressed: () {},
                      color: Color(0xFFDBDBDB),
                      textColor: Colors.white,
                      child: Text('募集结束'),
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
